package com.example.demo.service.impl;

import com.example.demo.Untils.PachongUtil;
import com.example.demo.entity.UUser;
import com.example.demo.mapper.UUserMapper;
import com.example.demo.service.IUUserService;
import com.example.demo.service.LoginService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by Administrator on 2017/11/1/001.
 */
@Service
public class LoginServiceImpl implements LoginService{
    @Autowired
    private IUUserService iuUserService;

    @Override
    public Map<String, Object> submitRegis(String username, String password) {
        Map<String,Object> resultMap=new LinkedHashMap<>();

        if(StringUtils.isBlank(username)){
            resultMap.put("msg","用户不能为空");
            return resultMap;
        }

        if(StringUtils.isBlank(password)){
            resultMap.put("msg","密码不能为空");
            return resultMap;
        }
        Map<String,Object> resultMap1=new LinkedHashMap<>();
        resultMap1.put("nickname",username);

        List<UUser> uUsers=iuUserService.selectByMap(resultMap1);
        if(uUsers.size()>0){
            resultMap.put("msg","用户名已经被注册");
            return resultMap;
        }

        UUser user=new UUser();

        user.setNickname(username);
        String salt= UUID.randomUUID().toString().substring(0,5);
        user.setEmail(salt);
        String pass= PachongUtil.MD5(password+user.getEmail());
        user.setPswd(pass);
        user.setCreateTime(new Date());
        iuUserService.insert(user);
        return resultMap;
    }
}
